package com.zll.dms.pojo;

import com.zll.dms.constants.Constants;
import lombok.Data;

@Data
public class ResultData {


    private int status;

    private String message;

    private Object data;

    /**
     * 创建返回对象
     * @param data
     * @param message
     * @param status
     * @return
     */
    private static ResultData createResult(Object data, String message, int status) {
        ResultData resultData = new ResultData();
        resultData.setData(data);
        resultData.setStatus(status);
        resultData.setMessage(message);
        return resultData;
    }

    /**
     * 创建成功对象
     * @param data
     * @param message
     * @return
     */
    private static ResultData createSuccess(Object data, String message) {
        return createResult(data, message, Constants.RESPONSE_STATUS_SUCCESS);
    }

    /**
     * 创建失败对象
     * @param data
     * @param message
     * @return
     */
    private static ResultData createError(Object data, String message) {
        return createResult(data, message, Constants.RESPONSE_STATUS_ERROR);
    }


    /**
     * 成功执行-data
     * @param data
     * @return
     */
    public static ResultData success(Object data) {
        return createSuccess(data, "");
    }

    /**
     * 成功执行-
     * @return
     */
    public static ResultData success() {
        return createSuccess(null, "");
    }

    /**
     * 成功执行-message
     * @return
     */
    public static ResultData success(String message) {
        return createSuccess(null, message);
    }

    /**
     * 成功执行-message/data
     *
     * @return
     */
    public static ResultData success(Object data, String message) {
        return createSuccess(data, message);
    }

    /**
     * 错误-message/data
     * @param message
     * @return
     */
    public static ResultData error(String message,Object data) {
        return createError(data, message);
    }

    /**
     * 错误-message
     * @param message
     * @return
     */
    public static ResultData error(String message) {
        return createError(null, message);
    }

    /**
     * 错误-
     * @return
     */
    public static ResultData error() {
        return createError(null,"");
    }

    /**
     * 创建需登录对象
     * @return
     */
    public static ResultData createNoLogin() {
        return createResult(null, "请先登录", Constants.RESPONSE_STATUS_NOLOGIN);
    }

    /**
     * 创建需无权限对象
     * @return
     */
    public static ResultData createNoRight() {
        return createResult(null, "抱歉您无此权限", Constants.RESPONSE_STATUS_NORIGHT);
    }

}
